﻿namespace USElections.Converters
{
    using System;
    using System.Windows.Data;
    using USElections.Model;

    public class CandidateToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Candidate candidate = null;

            try
            {
                 candidate = Data.Instance.Candidates.GetCandidateByFullname(value.ToString());
            }
            catch
            {
            }

            Candidate.Parties party = Candidate.Parties.None;

            if (candidate != null)
            {
                party = candidate.Party;
            }

            PartyToColorConverter ptc = new PartyToColorConverter();

            return ptc.Convert(party, targetType, parameter, culture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
